home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Internet / Icons (cicn) to HTML < prev    next >
Encoding:
Text File  |  1999-03-04  |  4.0 KB  |  146 lines  |  [TEXT/ToyS]

  1. property kasWinDims : {320, 240}
  2. property kasHtHead : {"<HTML>", "<HEAD>", "<TITLE>", "Akua's Icon Table", "</TITLE>", "</HEAD>", "<BODY>"}
  3. property kasHtTail : {"</BODY>", "</HTML>"}
  4. property kasTblHead : {"<TABLE BORDER=4 CELLPADDING=4 CELLSPACING=2>"}
  5. property kasRowHead : {"<TR>", "<TD VALIGN=top>"} -- Name goes after this
  6. property kasRowDiv1 : {"</TD>", "<TD VALIGN=top>"} -- Number goes after this
  7. property kasRowDiv2 : {"</TD>", "<TD>"} -- Img tag goes after this
  8. property kasRowTail : {"</TD>", "</TR>"}
  9. property kasTblTail : {"</TABLE>"}
  10.  
  11. property kasImgTag : "<IMG"
  12. property kasImgH : "HEIGHT"
  13. property kasImgW : "WIDTH"
  14. property kasImgSrc : "SRC"
  15.  
  16. property kasExportFormat : "JPEG" -- QT Supports JPEG, BMP or QTIF but not GIF
  17. property kasExtension : ".jpg"
  18.  
  19. global gasDrawWin
  20.  
  21.  
  22. on open fsObjs
  23.     repeat with fsObj in fsObjs
  24.         set gasDrawWin to ¬
  25.             display drawing titled ¬
  26.                 "Color Icons to HTML" with dimensions kasWinDims
  27.         
  28.         -- Create output folder
  29.         set fsInf to extended info for fsObj
  30.         set fsDad to (parent spec of fsInf) as string
  31.         set outFold to («event ÅkuFƒNew» fsDad given «class NAME»:"icons") as string
  32.         
  33.         -- Start stuff
  34.         set winBox to {0, 0} & kasWinDims
  35.         set icnBox to {0, 16} & kasWinDims
  36.         set txtBox to {0, 0, item 1 of kasWinDims, 16}
  37.         set html to kasHtHead & kasTblHead
  38.         
  39.         -- Black background
  40.         draw a box into gasDrawWin ¬
  41.             inside of winBox ¬
  42.             filling it with the pen
  43.         
  44.         -- Get icons
  45.         set idx to 1
  46.         repeat while true
  47.             try
  48.                 set ciRsc to the resource in fsObj ¬
  49.                     of type ¬
  50.                     "cicn" with index idx ¬
  51.                     with its info
  52.             on error
  53.                 exit repeat
  54.             end try
  55.             
  56.             -- Break it down
  57.             set ciName to item 1 of ciRsc
  58.             set ciNum to item 2 of ciRsc
  59.             set ciData to item 3 of ciRsc
  60.             
  61.             -- Convert to picture, get bounds        
  62.             set ciPic to ciData as picture
  63.             set ciInf to the picture info for ciPic
  64.             set ciBox to picture bounds of ciInf
  65.             set ciDrawBox to CenterBox(ciBox, icnBox)
  66.             
  67.             -- Add row to table
  68.             set ciW to compile tag val {kasImgW, (item 3 of ciBox) - (item 1 of ciBox)}
  69.             set ciH to compile tag val {kasImgH, (item 4 of ciBox) - (item 1 of ciBox)}
  70.             set ciS to compile tag val {kasImgSrc, "icons/" & ciNum & kasExtension}
  71.             set imgTag to compile tag {kasImgTag, ciW, ciH, ciS}
  72.             set html to html & kasRowHead & ciName & kasRowDiv1 & ("#" & ciNum) & kasRowDiv2 & imgTag & kasRowTail
  73.             
  74.             -- Erase background
  75.             draw a box into gasDrawWin ¬
  76.                 inside of winBox ¬
  77.                 filling it with the pen ¬
  78.                 without recording
  79.             
  80.             -- Show name
  81.             draw a text box into gasDrawWin ¬
  82.                 inside of txtBox ¬
  83.                 using data ciName ¬
  84.                 using state {text mode:2} ¬
  85.                 justified flush left ¬
  86.                 without recording
  87.             
  88.             -- Show number
  89.             draw a text box into gasDrawWin ¬
  90.                 inside of txtBox ¬
  91.                 using data ("Idx:" & idx & " #" & ciNum) ¬
  92.                 using state {text mode:2} ¬
  93.                 justified flush right ¬
  94.                 without recording
  95.             
  96.             -- Draw Icon
  97.             draw a picture into gasDrawWin ¬
  98.                 inside of ciDrawBox ¬
  99.                 using data ciPic ¬
  100.                 without recording
  101.             
  102.             -- Save file
  103.             store image ciPic ¬
  104.                 in (outFold & ciNum & kasExtension) ¬
  105.                 given «class îKnd»:kasExportFormat
  106.             
  107.             -- Advance to next 'cicn'
  108.             set idx to idx + 1
  109.             --        if (idx > 100) then exit repeat -- Just testing
  110.         end repeat
  111.         
  112.         set html to html & kasTblTail & kasHtTail
  113.         set htTxt to compile ML html
  114.         
  115.         -- Write html to file
  116.         set fRef to ¬
  117.             open fork from fsDad ¬
  118.                 named "icon_index.html" of type "TEXT" of creator "R*ch" with write access
  119.         write data to fRef from buffer htTxt
  120.         close fork fRef
  121.     end repeat
  122. end open
  123.  
  124.  
  125. on quit
  126.     display drawing gasDrawWin with disposal
  127.     return (continue quit)
  128. end quit
  129.  
  130.  
  131. on CenterBox(src, dst)
  132.     -- Place src in dst w/o scaling
  133.     set dX to (item 1 of dst)
  134.     set dY to (item 2 of dst)
  135.     set sW to (item 3 of src) - (item 1 of src)
  136.     set sH to (item 4 of src) - (item 2 of src)
  137.     set dW to (item 3 of dst) - dX
  138.     set dH to (item 4 of dst) - dY
  139.     
  140.     set bW to dX + (dW - sW) / 2
  141.     set bH to dY + (dH - sH) / 2
  142.     
  143.     -- Center it
  144.     return {bW, bH, bW + sW, bH + sH}
  145. end CenterBox
  146.